class Solution {
public:
    int wiggleMaxLength(vector<int>& nums) {
        if (nums.size() == 1) return 1;
        int ans = 1;
        int prediff = 0;
        int curdiff = 0;
        for (int i = 0; i < nums.size() - 1; ++i)
        {
            curdiff = nums[i + 1] - nums[i];
            if ((prediff <= 0 && curdiff > 0) || (prediff >= 0 && curdiff < 0))
            {
                ++ans;
                prediff = curdiff;
            }
        }
        return ans;
    }
};